//
//  CJNetWork.m
//  TMSDriver
//
//  Created by mac on 2019/3/15.
//  Copyright © 2019年 zhuchongjin. All rights reserved.
//

#import "CJNetWork.h"
#import "AppDelegate.h"
#import "OrderListDetailModel.h"
#import "HDPicModle.h"
#import "SourceListDetailModel.h"

@implementation CJNetWork

+ (void)getPartyUserCenterInfoSuccess:(Success )suceeinfo{
    
    NSString *strUrl = CJStringWithFormat(@"%@/ntocc-basic-api/party/userCenter",CJBaseUrl);
    NSDictionary *dicPra = nil;
    
    [[HDNetworking sharedHDNetworking] GET:strUrl parameters:dicPra success:^(id  _Nonnull responseObject) {
        
//        CJRemoveMyDefault(CJPartyUserCenter);
        CJSaveMyDefault(CJPartyUserCenter, (NSDictionary *)responseObject);
        suceeinfo(responseObject);
    } failure:^(NSError * _Nonnull error) {

    }];
        
}

+ (void)getShipmentInfoSuccess:(Success )suceeinfo{
    
    NSDictionary *dict = [[NSDictionary alloc]init];
    [[HDNetworking sharedHDNetworking] GET:CJStringWithFormat(@"%@/ntocc-basic-api/shipment/info",CJBaseUrl) parameters:dict success:^(id  _Nonnull responseObject) {
    
        suceeinfo(responseObject);

    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];

}


/// 获取必填非必填     driver 司机 driverTeam 车队 teamDriver 车队司机 shipment 货主 shipmentCompany 企业货主
/// @param strType <#strType description#>
/// @param suceeinfo <#suceeinfo description#>
+ (void)getFieldRequiredSetting:(NSString *)strType InfoSuccess:(Success )suceeinfo{
    
    NSDictionary *dict = @{
        @"fieldFrom":strType
    };
    [[HDNetworking sharedHDNetworking] GET:CJStringWithFormat(@"%@/ntocc-basic-api//fieldRequiredSetting/findByFieldFrom",CJBaseUrl) parameters:dict success:^(id  _Nonnull responseObject) {

        suceeinfo(responseObject);

    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);

    }];

}

+ (void)getSenGoodsDicsTypeinfo:(CJGetSendGoodsType )goodsType Success:(Success )suceeinfo{
    
    NSString *str = @"";
    NSString *strUrl = CJStringWithFormat(@"%@/ntocc-basic-api/dict/listDict",CJBaseUrl);

    switch (goodsType) {
        case CJGetSendGoodVehicleLength:
            str = @"vehicleLength";
            break;
        
         case CJGetSendgoodsTransferFeeUnits:
            str = @"goodsTransferFeeUnits";
            break;
            
        case CJGetSendgoodsvehicleLengthClass:
           str = @"vehicleLength,vehicleClassification";
           break;
            
        case CJGetSendgoodslimitWastageType:
            str = @"limitWastageType";
            break;
            
        case CJGetSendgoodsInsureType:
            str = @"insureType1";
//            strUrl = CJStringWithFormat(@"%@/ntocc-basic-api/dict",CJBaseUrl);
            break;
//            迭代去掉 21-08-13
//        case CJGetSendgoodsBillingType:
//            str = @"billingType";
            break;
        case CJGetSendgoodsBank:
            str = @"bank";
            break;
        case CJGetPriceItem:
            str = @"priceItem";
            break;
        case CJExtraFeeType:
            str = @"extraFeeType";
            break;
        case CJAbnormalType:
            str = @"abnormalType";
            break;
            
        case CJTransportType:
            
            str = @"transportType";
            break;
        case CJAlctGoodsType:
            str = @"alctGoodsType";
            break;
        case CJAlctGoodsClass:
            str = @"alctGoodsClass";
            break;
        
        case CJInsureGoods:
            str = @"insureGoods";
            break;
        case CJCardType:
            str = @"cardType";
            break;
        default:
            break;
    }
    
    NSDictionary *dicPra = @{
                             @"types":str
                            };
    
    [[HDNetworking sharedHDNetworking] GET:strUrl parameters:dicPra success:^(id  _Nonnull responseObject) {
           
        suceeinfo(responseObject);

    } failure:^(NSError * _Nonnull error) {
        
    }];
    
}



+ (void)getCommonRouteDistance:(NSDictionary *)dic Success:(Success )suceeinfo{
    
    [[HDNetworking sharedHDNetworking] POST:CJStringWithFormat(@"%@/ntocc-tps-api/amapApi/getGeocodes",CJBaseUrl) parameters:dic success:^(id  _Nonnull responseObject) {
             
        suceeinfo(responseObject);
        
    } failure:^(NSError * _Nonnull error) {
//        DLog(@"++++++++%@",error);
        
    }];

}


/// 通过经纬度获取距离
/// @param dic <#dic description#>
/// @param suceeinfo <#suceeinfo description#>
+ (void)getCommonRouteDistanceByLatLong:(NSDictionary *)dic Success:(Success )suceeinfo{
    
    [[HDNetworking sharedHDNetworking] POST:CJStringWithFormat(@"%@/ntocc-tps-api/amapApi/getDistance",CJBaseUrl) parameters:dic success:^(id  _Nonnull responseObject) {
             
        suceeinfo(responseObject);
        
    } failure:^(NSError * _Nonnull error) {
//        DLog(@"++++++++%@",error);
        
    }];
}


+ (void)deleteOrderListWithCodes:(NSString *)strCode Success:(Success )suceeinfo{
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/order",CJBaseUrl);
    NSDictionary *dicPar = @{
                             @"codes":strCode
                            };
//    @weakify(self);
    [[HDNetworking sharedHDNetworking] dataTaskWithHTTPMethod:DeleteType url:strURL parameters:dicPar status:OperationTip success:^(id  _Nonnull responseObject){
        
        suceeinfo(responseObject);

    } failure:^(NSError * _Nonnull error) {
        
    }];
    
}
+ (void)stopOrderListWithCodes:(NSString *)strCode Success:(Success )suceeinfo{
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/order/cancelOrder",CJBaseUrl);
    NSDictionary *dicPar = @{
                             @"codes":strCode
                            };

    [[HDNetworking sharedHDNetworking] dataTaskWithHTTPMethod:PutType url:strURL parameters:dicPar status:OperationTip success:^(id  _Nonnull responseObject) {
        
        suceeinfo(responseObject);
    } failure:^(NSError * _Nonnull error) {
        
    }];
}
+ (void)refreshOrderListWithCodes:(NSString *)strCode Success:(Success )suceeinfo{
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/order/flushOrder",CJBaseUrl);
    NSDictionary *dicPar = @{
                             @"codes":strCode
                            };
//    @weakify(self);
    [[HDNetworking sharedHDNetworking] dataTaskWithHTTPMethod:PutType url:strURL parameters:dicPar status:OperationTip success:^(id  _Nonnull responseObject) {
        
        suceeinfo(responseObject);
    } failure:^(NSError * _Nonnull error) {
        
    }];
    
}


/// 运单详情
/// @param strCode <#strCode description#>
/// @param suceeinfo <#suceeinfo description#>
+ (void)getSourcesOrderListDetailDataWithCode:(NSString *)strCode Success:(Success )suceeinfo{
    
    NSString *strUrl = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/%@",CJBaseUrl,strCode); //1d78851c7b7d4243a219ce0831a75fce
    NSDictionary *dic = [[NSDictionary alloc]init];
    [[HDNetworking sharedHDNetworking] GET:strUrl parameters:dic success:^(id  _Nonnull responseObject) {
       
       NSError * error ;
       OrderListDetailModel *model = [[OrderListDetailModel alloc] initWithDictionary:responseObject error:&error];
       suceeinfo(model);

    } failure:^(NSError * _Nonnull error) {
       DLog(@"++++++++%@",error);
       
    }];

}


/// 货源单详情
/// @param strCode <#strCode description#>
/// @param suceeinfo <#suceeinfo description#>
+ (void)getSourcesListDetailDataWithCode:(NSString *)strCode Success:(Success )suceeinfo{
    
    NSString *strUrl = CJStringWithFormat(@"%@/ntocc-tms-api/order/%@",CJBaseUrl,strCode); //1d78851c7b7d4243a219ce0831a75fce
    NSDictionary *dic = [[NSDictionary alloc]init];
    [[HDNetworking sharedHDNetworking] GET:strUrl parameters:dic success:^(id  _Nonnull responseObject) {
       
    NSError * error ;
    SourceListDetailModel *model = [[SourceListDetailModel alloc] initWithDictionary:responseObject error:&error];
    suceeinfo(model);

    } failure:^(NSError * _Nonnull error) {
       DLog(@"++++++++%@",error);
       
    }];

}


/// 上传照片
/// @param img <#img description#>
/// @param imageData <#imageData description#>
/// @param suceeinfo <#suceeinfo description#>
+ (void)upLoadImageUImage:(UIImage *_Nullable)img withNSData:(NSData *_Nullable)imageData Success:(Success )suceeinfo{
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tps-api/fileUpload",CJBaseUrl);

    NSURL *str = [[NSURL alloc]initFileURLWithPath:[CJControl getImgFilePath:img]];

    NSDictionary *dic = @{
                          @"file":str
                          };
    HDPicModle *model = [[HDPicModle alloc]init];
    model.pic = img;
    model.picData = imageData;
    model.picName = @"file";
    model.fileName = [CJControl getImgFilePath:img];

//    @weakify(self);
    [[HDNetworking sharedHDNetworking] POST:strURL parameters:dic andPic:model progress:^(NSProgress * _Nullable progress) {
         DLog(@"%lf", 1.0 * progress.completedUnitCount / progress.totalUnitCount);
    } success:^(id  _Nonnull responseObject) {

        NSString *strStatus = CJStringWithFormat(@"%@",responseObject[@"status"]);
        DLog(@"====== %@",responseObject);
        if (strStatus.integerValue == 0) {

//            [ws uploadImgVURLGetData:responseObject[@"data"]];
            suceeinfo(responseObject[@"data"]);
        }else{
            [CJAlert showStringDismissWithDelay:responseObject[@"msg"]];
        }

    } failure:^(NSError * _Nonnull error) {
        DLog(@"+++++++%@",error);

    }];
    
}


/// 获取 code信息等
/// @param suceeinfo <#suceeinfo description#>
+ (void)getBrachcCodeSuccess:(Success )suceeinfo{
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-basic-api/partyGroup/getDefault",CJBaseUrl);
    NSDictionary *dicPar = nil;
    
//    @weakify(self);
    [[HDNetworking sharedHDNetworking] GET:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {

        CJSaveMyDefault(CJPartyGroupDefault, responseObject);
        suceeinfo(responseObject);
       
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];

}


/// 获取机构列表list
/// @param suceeinfo <#suceeinfo description#>
+ (void)getBrachcCodeListSuccess:(Success )suceeinfo{
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-basic-api/partyGroup/list?type=1",CJBaseUrl);

    [[HDNetworking sharedHDNetworking] dataTaskWithHTTPMethod:GetType url:strURL parameters:@{} status:ArpaDefault success:^(id  _Nonnull responseObject) {
        
        suceeinfo(responseObject);
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

+ (void)getHomeVCMessageNoReadSumSuccess:(Success )suceeinfo{
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-basic-api/jpushMessage/unreadTotal",CJBaseUrl);
 
//    @weakify(self);
    NSDictionary *dic = [[NSDictionary alloc]init];
    [[HDNetworking sharedHDNetworking] GET:strURL parameters:dic success:^(id  _Nonnull responseObject) {
        
         suceeinfo(responseObject);
        
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];

}
@end
